﻿using HPITSSBLL;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using HPITSSModel;

namespace HPITSSDAL
{
   public class TruckTeamDAL
    {
        public static SqlDataReader TruckTeamInfo()
        {
            string sql = "select top 3 * from TruckTeam where Isdelete=0";
            SqlParameter[] para = new SqlParameter[]
           {
           };
            SqlDataReader dt = DBHelper.ExecuteReader(sql, para);
            return dt;
        }
        public static int DelectTruckTeam(string TeamID)
        {
            string sql = "update TruckTeam set Isdelete=1 where TeamID=@TeamID";
            SqlParameter[] paras = new SqlParameter[]
            {
                new SqlParameter("@TeamID",TeamID)
            };
            return DBHelper.ExecuteNonQuery(sql, paras);
        }
        public static List<TruckTeam> TruckTeamViewModel(SqlDataReader read)
        {
            List<TruckTeam> Trucklist = new List<TruckTeam>();
            while (read.Read())
            {
                TruckTeam t = new TruckTeam();
                t.TeamID = Convert.ToInt32(read["TeamID"]);
                t.TeamName = read["TeamName"].ToString();
                t.Leader = read["Leader"].ToString();
                t.Remark = read["Remark"].ToString();
                t.CheckInTime = Convert.ToDateTime(read["CheckInTime"]);
                t.IsDelete = Convert.ToInt32(read["IsDelete"]);
                t.AlterTime = Convert.ToDateTime(read["AlterTime"]);
                Trucklist.Add(t);
            };
            //关闭连接
            read.Close();
            //返回数据
            return Trucklist;
        }
        /// <summary>
        /// 修改要编辑的信息
        /// </summary>
        /// <param name="TeamID"></param>
        /// <returns></returns>
        public static TruckTeam EditTruckInfo(string TeamID)
        {
            string sqlstr = "select * from TruckTeam where TeamID=@TeamID";
            SqlParameter[] paras = new SqlParameter[]
            {
                new SqlParameter("@TeamID",TeamID)
            };
            SqlDataReader read = DBHelper.ExecuteReader(sqlstr, paras);
            List<TruckTeam> truck = TruckTeamViewModel(read);
            return truck[0];
        }
    }
   
}
